package com.itheima.demo;

import java.io.*;

public class Demo01 {//存储多个对象到对象流中
    public static void main(String[] args) throws IOException {
        //创建对象序列化流
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("day017\\a.txt"));
        //写对象
        oos.writeObject(new Student("张三",33));
        oos.writeObject(new Student("王爱",20));
        oos.writeObject(new Student("铁板钉",100));
        oos.writeObject(new Student("王二狗",70));
        //释放资源
        oos.close();

        //创建反序列化流
        ObjectInputStream ois =new ObjectInputStream(new FileInputStream("day017\\a.txt"));
        //读数据
        while(true){
            try {
                Student s =(Student) ois.readObject();
                System.out.println(s);
            } catch (IOException | ClassNotFoundException e) {
               break;
            }
        }
        //释放资源
        ois.close();
    }
}
